package demo008;
/**
 * 使用Thread 创建线程
 * @author zangyiwei 
 * @email zanglaowei@163.com
 * @date 2020年7月7日
 */
public class demoThread extends Thread {

	private String threadName;
	
	demoThread( String name) {
		threadName = name;
	}
	/**
	 * 要对Thread的run方法进行重写
	 */
	public void run() {
		System.out.println("Running " +  threadName );
		try {
			for(int i = 10; i > 0; i--) {
			    System.out.println("Thread: " + threadName + ", " + i);
			    // 让线程睡眠一会
			    Thread.sleep(50);
			} 
		}
		catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("Thread " +  threadName + " interrupted.");
		}

		System.out.println("Thread " +  threadName + " exiting.");
   }
	   
	public static void main (String args[]) {
		demoThread t = new demoThread ("ThreadName");
		//启动多线程
		t.start ();
		// 只是调用run
//		t.run();
		
		for(int i = 1000; i > 0; i--) {
		    System.out.println("--------main-----------------");
		} 
		
		
	}
}
